package com.scuec.tourismwebsite.mapper;

import com.scuec.tourismwebsite.entity.PostFavorite;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PostFavoriteMapper {
    @Insert("INSERT INTO post_favorite (post_id, user_id) VALUES (#{post_id}, #{user_id})")
    public int insertPostFavorite(@Param("user_id") int user_id, @Param("post_id") int post_id);

    @Select("SELECT * FROM post_favorite where user_id=#{user_id} and post_id=#{post_id}")
    public List<PostFavorite> selectPostFavoriteById(@Param("user_id") int user_id, @Param("post_id") int post_id);

    @Delete("DELETE FROM post_favorite where user_id=#{user_id} and post_id=#{post_id}")
    public int deletePostFavorite(@Param("user_id") int user_id, @Param("post_id") int post_id);

    @Select("SELECT pf.*, p.title, p.content, p.image_1 " +
            "FROM post_favorite pf " +
            "JOIN post p ON pf.post_id = p.post_id " +
            "WHERE pf.user_id = #{user_id}")
    List<PostFavorite> getUserFavorites(@Param("user_id") Integer user_id);
}

